<template>
  <div ref="split" class="split">
    <div class="left">
      占位符111
      <button @click="sendMessage">发送</button>
    </div>
    <NodeTree class="node-tree" ref="nodeTreeRef" :data="JSON.parse(testData) || []" @updateForm="handleUpdate" />
  </div>
</template>

<script lang="ts" setup>
import { onMounted } from "vue";

defineOptions({
  name: "AdjustList"
});

import NodeTree from "mctp-platform/components/public/NodeTree/index.vue";
// import type { nodeItem } from "mctp-platform/components/public/NodeTree/index.js";

const handleUpdate = (data: any) => {
  console.log("handleUpdate", data);
  // 这里可以处理更新逻辑
};

onMounted(() => {
  const channel = new BroadcastChannel('test-channel');
  channel.onmessage = (e) => {
    console.log("插件监听的数据触发", e.data);
    // console.log(e.data);
  }; // 应收到 'Test from A'

});

const sendMessage = () => {
  console.log("发送消息");
  const channel = new BroadcastChannel('test-channel');
  channel.postMessage({ type: 'plugin-message', payload: 'Hello from Plugin!' });
};


const testData = `[
  {
    "value": "10",
    "minInclusive": -60,
    "maxInclusive": 30,
    "name": "发射功率",
    "controlType": "Integer",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "10",
    "minInclusive": 0,
    "maxInclusive": 80,
    "name": "内部衰减(dBm)",
    "controlType": "Integer",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "10",
    "minInclusive": -60,
    "maxInclusive": 30,
    "name": "参考电平(dBm)",
    "controlType": "Integer",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "100kHz",
    "constraint": [
      "1kHz",
      "3kHz",
      "10kHz",
      "30kHz",
      "100kHz",
      "300kHz",
      "1MHz",
      "3MHz"
    ],
    "name": "RBW",
    "controlType": "Enum",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "300kHz",
    "constraint": [
      "3kHz",
      "10kHz",
      "30kHz",
      "100kHz",
      "300kHz",
      "1MHz",
      "3MHz",
      "10MHz"
    ],
    "name": "VBW",
    "controlType": "Enum",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "10",
    "minInclusive": 0,
    "maxInclusive": 100,
    "name": "Span(MHz)",
    "controlType": "Integer",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": true,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "频段列表1",
    "constraint": [
      "频段列表1"
    ],
    "name": "频段列表",
    "controlType": "Enum",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": false,
    "isReadOnly": false,
    "descirbe": null
  },
  {
    "value": "参考链路1",
    "constraint": [
      "参考链路1",
      "参考链路2"
    ],
    "name": "参考链路",
    "controlType": "Enum",
    "assemblyName": null,
    "sourceType": null,
    "isRequired": false,
    "isReadOnly": false,
    "descirbe": null
  }
]`;

</script>
<style scoped lang="scss">
.split {
  display: flex;

  .left {
    width: 100px;
    border: 1px solid red;
  }

}
</style>
